package wb_view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import model.ParkingAreaManager;
import vo.ParkHistory;

public class DetailedInformation extends JFrame {

	private String date, area;
	
	private JPanel contentPane;
	private JTextField jfieldArea;
	private JTextField jfieldDate;
	private JScrollPane scrollPane;
	private JTable table;
	private String[] table_header = {"입차시간.","출차시간.","차량번호.","주차요금."};
	private JLabel jlabelARea;
	private JLabel jlabelDate;
	private JButton jbtnClose;


	/**
	 * Create the frame.
	 */
	JFrame target;
	public DetailedInformation(String date, String area) {
		
		this.target = target;
		
		this.date = date;
		this.area = area;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 500,400);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		jfieldArea = new JTextField();
		jfieldArea.setBounds(96, 29, 116, 21);
		jfieldArea.setText(area);
		contentPane.add(jfieldArea);
		jfieldArea.setColumns(10);
		
		jfieldDate = new JTextField();
		jfieldDate.setBounds(296, 29, 116, 21);
		jfieldDate.setText(date);
		contentPane.add(jfieldDate);
		jfieldDate.setColumns(10);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(27, 92, 426, 260);
		contentPane.add(scrollPane);
		
		jlabelARea = new JLabel("\uC8FC\uCC28\uAD6C\uC5ED");
		jlabelARea.setBounds(27, 32, 57, 15);
		contentPane.add(jlabelARea);
		
		jlabelDate = new JLabel("\uB0A0\uC9DC");
		jlabelDate.setBounds(243, 32, 41, 15);
		contentPane.add(jlabelDate);
		
		jbtnClose = new JButton("\uB2EB\uAE30");
		jbtnClose.setBounds(306, 59, 97, 23);
		contentPane.add(jbtnClose);
		
		setDetailedInfo();
				
		ActionListener al_close = new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{				
				
			if(ae.getSource()==jbtnClose)
			{
			
				dispose();
			
			}
				
			}
			
				
		};
		
		
		jbtnClose.addActionListener(al_close);
		
	}
	
	private void setDetailedInfo() {
		
		DefaultTableModel model = new DefaultTableModel(table_header,0);
		table = new JTable(model);
		scrollPane.setViewportView(table);
		ArrayList<ParkHistory> historyList = ParkingAreaManager.getInstance().getParkHistory(date, area);

		if(historyList == null)
			return;
		
		for(int i = 0; i < historyList.size(); ++i) {

			String[] contents = new String[4];

			contents[0] = historyList.get(i).getInTime();
			contents[1] = historyList.get(i).getOutTime();
			contents[2] = historyList.get(i).getCarNum();
			contents[3] = String.valueOf(historyList.get(i).getPrice());
			
			model.addRow(contents);
		}
	
		
	}
}
